package leetcode_周赛._2023._10;

/**
 * 第 369 场周赛
 * AC_2
 *
 * @author yezh
 * @date 2023/10/30 8:59
 */
public class _29 {

    /**
     * 2918. 数组的最小相等和
     * 算法：贪心
     */
    public long minSum(int[] nums1, int[] nums2) {
        boolean zero1 = false, zero2 = false;
        long s1 = 0, s2 = 0;
        for (int num : nums1) {
            if (num == 0) {
                zero1 = true;
                ++s1;
            } else s1 += num;
        }
        for (int num : nums2) {
            if (num == 0) {
                zero2 = true;
                ++s2;
            } else s2 += num;
        }
        if (s1 < s2 && !zero1 || s2 < s1 && !zero2) return -1;
        return Math.max(s1, s2);
    }

}
